package com.hckjsec.cloud.controller;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.hckjsec.common.utils.SecurityUtils;
import com.hckjsec.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.cloud.domain.AppletsSdkVerification;
import com.hckjsec.cloud.service.IAppletsSdkVerificationService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * SDK身份核验Controller
 * 
 * @author cyt
 * @date 2022-01-21
 */
@RestController
@RequestMapping("/system/sdkverification")
public class AppletsSdkVerificationController extends BaseController
{
    @Autowired
    private IAppletsSdkVerificationService appletsSdkVerificationService;

    /**
     * 查询SDK身份核验列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppletsSdkVerification appletsSdkVerification)
    {
        startPage();
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            appletsSdkVerification.setDeptId(SecurityUtils.getDeptId());
        }
        List<AppletsSdkVerification> list = appletsSdkVerificationService.selectAppletsSdkVerificationList(appletsSdkVerification);
        return getDataTable(list);
    }

    /**
     * 导出SDK身份核验列表
     */
    @Log(title = "SDK身份核验", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppletsSdkVerification appletsSdkVerification)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            appletsSdkVerification.setDeptId(SecurityUtils.getDeptId());
        }
        List<AppletsSdkVerification> list = appletsSdkVerificationService.selectAppletsSdkVerificationList(appletsSdkVerification);
        ExcelUtil<AppletsSdkVerification> util = new ExcelUtil<AppletsSdkVerification>(AppletsSdkVerification.class);
        return util.exportExcel(list, "verification");
    }

    /**
     * 获取SDK身份核验详细信息
     */
    @GetMapping(value = "/{orderNo}")
    public AjaxResult getInfo(@PathVariable("orderNo") String orderNo)
    {
        AppletsSdkVerification appletsSdkVerification = appletsSdkVerificationService.selectAppletsSdkVerificationById(orderNo);
        String sourcePhoto = StringUtils.isHcNull(appletsSdkVerification.getSourcePhoto(),"");
        String bestframe = StringUtils.isHcNull(appletsSdkVerification.getBestframe(),"");
        List<String> imgList = new ArrayList<>();
        if (!"".equals(sourcePhoto)){
            imgList.add(sourcePhoto);
        }
        if (!"".equals(bestframe)){
            imgList.add(bestframe);
        }
        appletsSdkVerification.setImgList(imgList);
        return AjaxResult.success(appletsSdkVerification);
    }
}
